import { getObjProperty, getFourVal } from '../utils';
// 绘制直线
import BaseElement from './element';
class Rect extends BaseElement {
    constructor(opts) {
        super(opts);
        const { points = [], style = {}, action = {} } = opts;
        this.beginPath = getObjProperty(action, 'beginPath', true);
        this.closePath = getObjProperty(action, 'closePath', true);
        this.save = getObjProperty(action, 'save', true);
        this.restore = getObjProperty(action, 'restore', true);
        this.stroke = getObjProperty(action, 'stroke', false);
        this.fill = getObjProperty(action, 'fill', true);
        let radius = getObjProperty(style, 'radius', '0');
        let r = getFourVal(radius);
        this.leftTopRadius = parseFloat(r.top);
        this.rightTopRadius = parseFloat(r.right);
        this.rightBottomRadius = parseFloat(r.bottom);
        this.leftBottomRadius = parseFloat(r.left);
        // this.offset = 0;
    }

    draw(ctx, path = false) {
        this.beforDraw(ctx, path);
        let { x, y, w, h } = this.points[0];
        let s_x = x - w / 2;
        let e_x = x + w / 2;

        let s_y = y - h / 2;
        let e_y = y + h / 2;

        let r1 = this.leftTopRadius;
        let r2 = this.rightTopRadius;
        let r3 = this.rightBottomRadius;
        let r4 = this.leftBottomRadius;
        ctx.moveTo(s_x, s_y + r1);
        ctx.arc(s_x + r1, s_y + r1, r1, Math.PI, (Math.PI * 3) / 2, false);
        ctx.lineTo(e_x - r2, s_y);
        ctx.arc(e_x - r2, s_y + r2, r2, (Math.PI * 3) / 2, Math.PI * 2, false);
        ctx.lineTo(e_x, e_y - r3);
        ctx.arc(e_x - r3, e_y - r3, r3, 0, Math.PI / 2, false);
        ctx.lineTo(s_x + r4, e_y);
        ctx.arc(s_x + r4, e_y - r4, r4, Math.PI / 2, (Math.PI * 3) / 2, false);
        ctx.lineTo(s_x, s_y + r1);
        this.afterDraw(ctx, path);
    }
    isPointIn(ctx, x, y) {
        return ctx.isPointInPath(x, y);
    }
    addPoint() {}
    update() {}
}
export default Rect;
